package thread;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张杰
 * Date: 2022-04-08
 * Time: 14:51
 */
class counter {
    public  int count;
    //普通的加锁方式
    /*synchronized public void increase() {
        count++;
    }*/

    //修饰一个代码块
     public void increase() {
         synchronized (this) {
             count++;
         }
     }
}

public class Demo3 {
    private static volatile int isQuit = 0;
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
             while (isQuit == 0) {

             }
            System.out.println("循环结束t线程退出!");
        });
        t.start();

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个isQuit的值:");
        isQuit = sc.nextInt();
        System.out.println("main线程执行完毕!");
    }
}
